<?php include view_path().'header_total.php'; ?>
<link rel='stylesheet' href='<?php echo css_url() . '960grid/960.css' ?>' />
<link rel='stylesheet' href='<?php echo css_url() . '960grid/960_extra.css' ?>' />
<link rel="stylesheet" type="text/css" href="<?php echo css_url() . 'display_style.css' ?>">
<!--- Dialog Addon --->
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.1/themes/base/jquery-ui.css">
<script src="http://code.jquery.com/ui/1.10.1/jquery-ui.js"></script>

<section id="body">
    <div class="body-container">
        <div class="heading">Information</div>

        <div class="container_12 margin-bottom"> 
            <div class="grid_2">
                <image style="width:100%" src="<?php echo $Post['PictureURL']?>">
            </div>

            <div class="grid_8 text-head">
                <div> Author: <a href="<?php echo site_url().'/user_group2/'.  urlencode($Post['Author']['UserGroup2ID']) ?>"><?php echo $Post['Author']['RelUserEmail']; ?> </a></div>
                <div> <?php echo $Post['Author']['CompanyName']; ?></div>
                <div class="describtion"> <?php echo $Post['Author']['Describtion']; ?></div>
                <?php if($Post['StatusCode'] == 0){

                }else if($Post['StatusCode'] == 1){
                    echo '<div class="status-panel-yellow">Waiting for acceptance</div>';
                }else if($Post['StatusCode'] == 2){
                    echo '<div class="status-panel-green">'.$Post['Recv']['Content'].'</div>';
                }
                ?>
            </div>
        </div>

        <div class="container_12 margin-bottom">
            <div class="grid_1 text-head" >Address: </div>
            <?php
            $Address = explode("@@", $Post['AddressWorkPlaces']);
            ?>
            <div class="grid_5 text"> <?php echo $Address[1] ?></div>

            <div class="grid_1 text-head" >Contact: </div>
            <?php
            $ContactContent = explode("@@", $Post['ContactContent']);
            ?>
            <div class="grid_5 text"> <?php echo nl2br($ContactContent[1]) ?></div>
        </div>
        <!-- Google Map Show -->
        <div class="container_12 margin-bottom">
                <div class="grid_1">&nbsp;</div>
                <?php if(!empty($Post['MoreAddress']['GoogleLink'])):?>
                <div class="grid_5">
                    <button id="address-button" class="show-map">Show Map</button>
                    <div class="map-container" style="position: absolute;left: -10000px;">
                        <iframe width="100%" height="500px" src="<?php echo $Post['MoreAddress']['GoogleLink'];?>"></iframe>
                    </div>
                </div>
                <?php endif;?>
                <div class="grid_1">&nbsp;</div>
                <?php if(!empty($Post['MoreContact']['GoogleLink'])):?>
                <div class="grid_5">
                    <button id="contact-button" class="show-map">Show Map</button>
                    <div class="map-container" style="position: absolute;left: -10000px;"> 
                        <iframe width="100%" height="500px" src="<?php echo $Post['MoreContact']['GoogleLink'];?>"></iframe>
                    </div>
                </div>
                <?php endif;?>
        </div>
        <!-- End of Google Map Show -->

        <div class="container_12 margin-bottom">
            <div class="grid_1 text-head" >Subject: </div>
            <div class="grid_5 text"> <?php echo $Post['Subject'] ?></div>

            <div class="grid_1 text-head" >Field: </div>
            <div class="grid_5 text"> <?php echo $Post['CategoryName'] ?></div>
        </div>     


        <div class="container_12 margin-bottom">
            <div class="grid_1 text-head" >Content: </div>
            <div class="grid_11 text"> <?php echo nl2br($Post['Content']); ?></div>
        </div>

        <!-- Ready Data for Requirement !-->
        <?php
            $RequirementArray = explode("##",$Post['MinimumRequirement']);
            $MainRequirement = $RequirementArray[0];
            $AdditionalRequirement = $RequirementArray[1];
            $CI =& get_instance();
            $CI->load->helper('string_addition');
        ?>
        <!-- Requirement Show Time !-->
        <div class="container_12 margin-bottom">
            <div class="grid_3 text-head" >Minimum Education Level:</div>
            <div class="grid_9 text"> <?php echo QualificationRecognize($MainRequirement); ?></div>
        </div>
        <div class="container_12 margin-bottom">
            <div class="grid_3 text-head" >Additional Requirement:</div>
            <div class="grid_9 text"> <?php echo ConvtAddQual($AdditionalRequirement); ?></div>
        </div>

        <div class="container_12 margin-bottom">
            <div class="grid_3 text-head" >Number of Applicant:</div>
            <div class="grid_9 text"> <?php echo $Post['NumApplicant']; ?></div>
        </div>

        <div class="container_12 margin-bottom">
            <div class="grid_10"> 
                <textarea id="IntroductionContent" class="text-input" name="IntroductionContent" 
                          placeholder="Introduce yourself" style="display:none;" rows="10"></textarea>
            </div>
        </div>

        
        <div class="container_12 margin-bottom">
            <div class="grid_8" id="error"
                 style="font-weight: bold; color: #FB6280"></div>
        </div>
        <div class="container_12 margin-bottom">
            <div class="grid_2"> 
                <?php
                if($Post['PA']){ ?>
                    <div id="apply" class="button-disabled">Apply</div>
                <?php }
                else { ?>
                    <div id="apply" class="button">Apply</div>
                <?php }
                ?>
            </div>
        </div>


    </div>
</section>

<script src="<?php echo asset_url() . "js/string_helper.js" ?>"></script>
<?php include js_url(true) . '/validate_things.php' ?>
<script>
    //Button Handler
    var StatusCode = <?php echo $Post['StatusCode'] ?>;
    var firstClick = true;

    var applyBtnHandler = function(){
        $('#apply').unbind('click');

        if(StatusCode == 0){
            apply();
        }else if(StatusCode == 1){
            $('#apply').on('click',function(){
                ConfirmDialog('Are you sure want to cancel this applyment',removeApply);
            });
        }else if(StatusCode == '2'){
             $('#apply').on('click',function(){
                $('#error').text('You have been seleceted. You cant cancel this right now. Please the owner of this post.');
            });
            
        }
    }
    
    var apply = function(){
        $('#apply').on('click',function(){
            if(firstClick){
                firstClick = false;
                $('#IntroductionContent').show();
            }
        
        else{
            Introduction = $('#IntroductionContent').val();
            $.ajax({
                url : '<?php echo site_url();?>/user_group3/jobs/apply/' + '<?php echo $Post["PostID"]?>',
                type: 'post',
                async: false,
                data: { IntroductionContent: Introduction },
                success: function(data){
                    if(data == 1)
                    {
                        alert("Successfully Apply!");
                        window.location.href = '<?php echo curPageURL(); ?>'
                    }
                    else{
                        alert("Failed to apply. Please try again");
                    }
                } 
            });
        }
    });
    }
    
    var removeApply = function(){
        $.ajax({
                url : '<?php echo site_url();?>/user_group3/jobs/remove_apply',
                type: 'post',
                data: {ID : '<?php echo $Post["PostID"]?>', PAID: '<?php if(!empty($Post['PA'])) echo $Post['PA']['PostApplyID']?>'},
                async: false,
                success: function(data){
                    if(data == 1 || data == '1')
                    {
                        alert('Successfully Cancel');
                       window.location.href = '<?php echo curPageURL(); ?>'
                    }
                    else{
                        alert("Failed to Remove. Please try again");
                    }
                } 
            });
    }
        //Confirm Dialog
        function ConfirmDialog(message, okfunction){
            $('<div></div>').appendTo('body')
                           .html('<div><h6>'+message+'?</h6></div>')
                           .dialog({
                               modal: true, title: 'Delete message', zIndex: 10000, autoOpen: true,
                               width: 'auto', resizable: false,
                               buttons: {
                                   Yes: function () {
                                       // $(obj).removeAttr('onclick');                                
                                       // $(obj).parents('.Parent').remove();

                                       $(this).dialog("close");
                                       okfunction();
                                   },
                                   No: function () {
                                       $(this).dialog("close");
                                   }
                               },
                               close: function (event, ui) {
                                   $(this).remove();
                               }
                           });
           };
           
    applyBtnHandler();
    //End of button handler
    // Google map Buttons
    var button_show_map = function(){$('button.show-map').on('click',function(){
        $(this).siblings('.map-container').css('left','0px');
        $(this).siblings('.map-container').css('position','');
        
        $(this).attr('class','hide-map');
        $(this).text("Hide Map");
        button_hide_map();
    });}

    var button_hide_map = function(){$('button.hide-map').on('click',function(){
        $(this).siblings('.map-container').css('left','-10000px');
        $(this).siblings('.map-container').css('position','absolute');
        
        $(this).attr('class','show-map');
        $(this).text("Show Map");
        button_show_map();
    });}
    
    button_show_map();
    // End of google map buttons
    
</script>

<?php include '/../../footer.php'; ?>